import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt.labs.qmlmodels

Rectangle {
    width: 300
    height: 400
    color: "#f0f0f0"

    ListView {
        id: indexListView
        anchors.fill: parent
        anchors.margins: 10
        spacing: 10
        clip: true

        model: ListModel {
            ListElement { value: 100; description: "特殊项目" }
            ListElement { value: 200; description: "常规项目" }
            ListElement { value: 300; description: "常规项目" }
            ListElement { value: 400; description: "常规项目" }
        }

        delegate: DelegateChooser {
            DelegateChoice {
                index: 0    //指定索引, 将index = 0的代理改为特殊样式
                delegate: Rectangle {
                    width: ListView.view.width
                    height: 80
                    color: "#2196F3"
                    radius: 8

                    ColumnLayout {
                        anchors.centerIn: parent
                        spacing: 5

                        Text {
                            text: model.description
                            color: "white"
                            font {
                                bold: true
                                pixelSize: 18
                            }
                            Layout.alignment: Qt.AlignHCenter
                        }
                    }
                }
            }

            DelegateChoice {
                // 不作任何指定属性， 表示通用代理
                delegate: Rectangle {
                    width: ListView.view.width
                    height: 60
                    color: "#E0E0E0"
                    radius: 4

                    RowLayout {
                        anchors {
                            fill: parent
                            margins: 10
                        }
                        spacing: 10

                        Text {
                            text: model.description
                            font.pixelSize: 14
                            Layout.fillWidth: true
                        }
                        Text {
                            text: model.value
                            font {
                                pixelSize: 14
                                bold: true
                            }
                        }
                    }
                }
            }
        }
    }
} 
